﻿// JScript 文件
var AssIoCfg =  
{
   JK_PRJ : 1100        //工程列表
  ,JK_ATT : 1200        //卡片列表
  ,JK_ATTCHG : 1300        //卡片变更列表
  ,JK_ZKP : 1400
  ,JK_ZKPCHG:1500
  ,JK_ATT1 : 1201        //工程卡片列表
  ,JK_ATT2 : 1202       //固定资产盘点列表        
  ,EX_PRJ : 2100        //工程列表
  ,EX_ATT : 2200        //卡片列表
  ,EX_ATTCHG : 2300        //卡片变更列表
  ,EX_ZKP : 2400        //资产实体列表
  ,EX_ZKPCHG : 2500        //资产变更列表
  ,EX_ZYDZ : 2600       //资源固定资产对照列表
  ,EX_ATT1 : 2201        //工程卡片列表
  ,EX_ATT2 : 2202       //固定资产盘点列表        

}
//资产服务命令
var AssCmd = 
{
    /// <summary>
    /// 返回成功信息
    /// </summary>
    RET_OK : "+OK",
    /// <summary>
    /// 返回错误信息
    /// </summary>
    RET_ERR : "-ERR",
    /// <summary>
    /// 命令分隔符
    /// </summary>
    SEPARATOR : " ",
    /// <summary>
    /// 按工程拆分
    /// </summary>
    CFBYPRJ : "CFBYPRJ",
    /// <summary>
    /// 按局站拆分
    /// </summary>
    CFBYJZ : "CFBYJZ",
    /// <summary>
    /// 按工程合并
    /// </summary>
    HBBYPRJ : "HBBYPRJ",
    /// <summary>
    /// 按局站合并
    /// </summary>
    HBBYJZ : "HBBYJZ",
    /// <summary>
    /// 合并父卡片
    /// </summary>
    HBFKP : "HBFKP",
    /// <summary>
    /// 合并子卡片
    /// </summary>
    HBZKP : "HBZKP",
    /// <summary>
    /// 按工程均摊
    /// </summary>
    JTBYPRJ : "JTBYPRJ",
    /// <summary>
    /// 按局站均摊
    /// </summary>
    JTBYJZ : "JTBYJZ",
    /// <summary>
    /// 询问状态
    /// </summary>
    STATUS : "STATUS",
    /// <summary>
    /// 退出
    /// </summary>
    EXIT : "EXIT",
    /// <summary>
    /// 帮助命令
    /// </summary>
    HELP : "HELP",
    /// <summary>
    /// 登陆
    /// </summary>
    LOGIN : "LOGIN",
    /// <summary>
    /// 分行符
    /// </summary>
    CRLF : "\r\n",
    /// <summary>
    /// 取消
    /// </summary>
    CANCEL : "CANCEL",
    /// <summary>
    /// 成功标志
    /// </summary>
    SUCCESS : "-1"
}

//IO配置字段对象
function AssIoFld(name, flag)
{
    this.name = name;
    this.flag = flag;
//    this.enable = enable;
}
//XML文档对象转字段对象数组
function xmlDocToObjList(xmlDoc)
{
    var arrFld = [];
    var root = xmlDoc.lastChild;
    for (var i = 0; i < root.childNodes.length; i++)
    {
        var node = root.childNodes[i];
        //arrFld.push(new AssIoFld($XML(node, "name"), parseInt($XML(node, "flag")), parseInt($XML(node, "enable"))));
        arrFld.push(new AssIoFld($XML(node, "name"), parseInt($XML(node, "flag"))));
    }
    return arrFld;
}
//字段对象数组转XML字符串
function objListToXmlStr(arrFld)
{
    var fldBuf = [];
    fldBuf.push("<m>");
    for (var i = 0; i < arrFld.length; i++)
    {
        fldBuf.push("<n ");
        fldBuf.push(' name="' + arrFld[i].name + '"');
        fldBuf.push(' flag="' + arrFld[i].flag + '"');
        fldBuf.push(" />");
    }
    fldBuf.push("</m>");
    return fldBuf.join("");
}
//字段对象数组转Cookie字符串
function objListToCookieStr(arrFld)
{
    var fldStr = new String();
    for (var i = 0; i < arrFld.length; i++)
    {
        fldStr += arrFld[i].name + "," + arrFld[i].flag + ";";//"," + arrFld[i].enable + 
    }
    if (fldStr)
    {
        fldStr = fldStr.substr(0, fldStr.length - 1);
    }
    return fldStr;
}
//Cookie字符串转字段对象数组
function CookieStrToObjList(fldStr)
{
    var arrFld = [];
    var arrFldStr = fldStr.split(";");
    for (var i = 0; i < arrFldStr.length; i++)
    {
        var arr = arrFldStr[i].split(",");
        arrFld.push(new AssIoFld(arr[0], parseInt(arr[1])));//, parseInt(arr[2])
    }
    return arrFld;
}
//
function getArrIoFld(kind)
{
    var arrFld = null;
    var fldStr = CtnCookie.get("ASSIOCFG" + kind);
    if (kind > 2000 && fldStr != null)
    {
        arrFld = CookieStrToObjList(unescape(fldStr));
    }
    else
    {
        var xmlDoc = CtnTrans.getXml("/main.ashx?_method=ASS_GetIoCfgXml", "post", "IoCfgType=" + kind); 
        if (!CtnError.validate(xmlDoc))
        {
            CtnError.show();
            return null;
        }
        arrFld = xmlDocToObjList(xmlDoc)
    }
    return arrFld;
}
//
function uiCfgToIoCfg(kind, isJk)
{
    var pre = "EX_";
    if (isJk)
    {
        pre = "JK_";
    }
    switch (kind)
    {
        case AssUiAttStyle.Prj:
            return AssIoCfg[pre + "PRJ"];
        case AssUiAttStyle.Fkp:
            return AssIoCfg[pre + "ATT"];
        case AssUiAttStyle.Fkp_Chg:
            return AssIoCfg[pre + "ATTCHG"];
        case AssUiAttStyle.Zkp:
            return AssIoCfg[pre + "ZKP"];
        case AssUiAttStyle.Zkp_Chg:
            return AssIoCfg[pre + "ZKPCHG"];
        case AssUiAttStyle.Prj_Fkp:
            return AssIoCfg[pre + "ATT1"];
        case AssUiAttStyle.ZyGdzcdz:
            return AssIoCfg[pre + "ZYDZ"];
        case AssUiAttStyle.Ext_Fkp:
            return AssIoCfg[pre + "ATT2"];
        default:
            return 0;
    }
}
function getEntByStyle(kind)
{
    switch (kind)
    {
        case AssUiAttStyle.Prj:
            return [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_ASSPRJINF];
        case AssUiAttStyle.Fkp_Chg:
            return [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_ASSETCHGCMB];
        case AssUiAttStyle.Zkp:
            return [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_ASSETZKPATT];
        case AssUiAttStyle.Zkp_Chg:
            return [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_ASSETCHANGE];
        case AssUiAttStyle.Fkp:
        case AssUiAttStyle.Prj_Fkp:
        case AssUiAttStyle.Ext_Fkp:
            return [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_ASSETATT];
        default:
            return [0, 0];
    }
}
function DpAction(strCmd, strParams)
{
    var dlg = CtnDlg.loading("正在初始化..<br/><br/>", onCancel, "AssetDlg");
    dlg.onClose = onCancel;
    CtnTrans.Ajax("/main.ashx","post", "_method=ASS_DpAction&Cmd=" + strCmd + "&Params=" + strParams, startDp);
}

function startDp(res)
{
    var text = res.responseText;
    if (!CtnError.validate(text))
    {
        CtnDlg.unloading("AssetDlg");
        CtnError.show();
        window.ASS_XDHD = null;
        return;
    }
    setTimeout("send()", 1000);
}
function showStat(res)
{
    var text = res.responseText;
    if (!CtnError.validate(text))
    {
        CtnDlg.unloading("AssetDlg");
        CtnError.show();
        window.ASS_XDHD = null;
        return;
    }
    var arrRes = text.split(AssCmd.SEPARATOR);
    if (arrRes[1] == AssCmd.SUCCESS)
    {
        CtnDlg.unloading("AssetDlg");
//        var dlg = CtnDlg.msg(arrRes.slice(2).join(AssCmd.SEPARATOR));
//        dlg.onClose = function (dlg)
//        {
        //向导回调
            if (window.ASS_XDHD)
            {
                window.ASS_XDHD();
                window.ASS_XDHD = null;
            }
//        }
        return;
    }
    var msg = arrRes.slice(2).join(AssCmd.SEPARATOR) + "<br />" + arrRes[0] + "/" + arrRes[1];
    CtnDlg.loading(msg, onCancel, "AssetDlg");
    setTimeout("send()", 1000);
}
function send()
{
    CtnTrans.Ajax("/main.ashx","post", "_method=ASS_DpQuery&Cmd=" + AssCmd.STATUS, showStat);
}
function onCancel(dlg)
{
    CtnTrans.Ajax("/main.ashx","post", "_method=ASS_DpQuery&Cmd=" + AssCmd.CANCEL, function(res){CtnDlg.unloading("AssetDlg");});
}